Now we are in the second exercise session. Non-flat files were promised, so please load the GESIS Panel COVID-19 data.

This first part of the exercises only deals with importing data. Later, in the second exercise, we will turn more to non-flat data files and label them before exporting.

1

Load the GESIS Panel COVID-19 data.
You can either load the SPSS or Stata file for which you need the haven package.
library(haven)

gp_covid <-
  read_spss("../data/ZA5667_v1-1-0.sav")

In contrast to the flat files, such as CSV, the variables now have labels. I wonder how the labels are for the first ten variables…

2

Print the labels of the first ten variables.
You can print labels with the function sjlabelled::get_label(your_data), but you have to make sure only to print the first ten variables.

Unfortunately, it’s all in German. Imagine you are an education researcher, and you are interested in the variable education_cat. So you may want to consider translating the variable into English, right?

3

Rename the variable label of age_cat from “Bildung, kategorisiert” into “Education, categorized”.
There a two ways: Either using the function sjlabelled::set_label() or do it in a pipe with sjlabelled::var_labels().
# either
gp_covid$education_cat <- 
  set_label(
    gp_covid$education_cat, 
    label = "Education, categorized"
  )

# or
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:sjlabelled':
## 
##     as_label
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
gp_covid <- 
  gp_covid %>% 
  var_labels(
    education_cat = "Education, categorized"
  )

# proof
get_label(gp_covid$education_cat)
## [1] "Education, categorized"

Your colleague asks you to provide your new data after changing labels and stuff. Unfortunately, she does not use R or SPSS and asks you to export your data as a Stata file.

4

Export your data as a Stata file.
Like in the case of importing, you again need the haven package.
write_stata(gp_covid, "gesis_panel_corona_fancy_panels_final_final.dta")